#include<stdio.h>
#include<pthread.h>
int g_val=0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void *test(void *arg)
{
	int count=5000;
	int tmp=0;
	while(count-->0)
	{
		pthread_mutex_lock(&mutex);
		tmp=g_val;
		printf("%sg_val=%d\n",arg,g_val);
		g_val=tmp+1;
		pthread_mutex_unlock(&mutex);
	}
}
int main()
{
	pthread_t thread1=0;
	pthread_t thread2=0;
	pthread_create(&thread1,NULL,test,"thread1");
	pthread_create(&thread2,NULL,test,"thread2");
	pthread_join(thread1,NULL);
	pthread_join(thread1,NULL);
	sleep(2);
	printf("the g_val=:%d\n",g_val);
}
